"""
按周期计算收益率，简单方法
"""
class top:
    def __init__(self,ascending=False,top=0.2,isna=True):
        self.ascending=ascending
        self.top=top
        self.isna=isna
    def oncalc(self,d,timekey=None):
        f=d.copy()
        f.sort_values(ascending=self.ascending,inplace=True)
        n = len(f)
        if not self.isna:
            f1 = f.loc[f.isna()]
            n=n-len(f1)
        n=int(n*self.top)
        if n>1:
            f2=f[:n]
            f.loc[:]=False
            f.loc[f2.index]=True
        else:
            f.loc[:] = False
        return f
